
//
//  LoginViewController.m
//  Codingke2016
//
//  Created by xujiangtao on 16/6/1.
//  Copyright © 2016年 xujiangtao. All rights reserved.
//

#import "LoginViewController.h"
#import "RegisterViewController.h"
#import "BaseLoginNavController.h"

@interface LoginViewController ()
@property (nonatomic,retain) UIScrollView* mainScrollView;
@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initInterface];
}
#pragma mark- initInterface
- (void)initInterface{
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"登录";
    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
    
    //取消 注册
    UIImage* cancelImage = [UIImage imageNamed:@"img_nav_cancel_btn"];
    UIImage* regImage = [UIImage imageNamed:@"img_nav_reg_btn"];
    
    UIBarButtonItem* cancelBarButtonItem = [[UIBarButtonItem alloc] initWithImage:cancelImage style:UIBarButtonItemStylePlain target:self action:@selector(clickCancelButton)];
    UIBarButtonItem* regBarButtonItem = [[UIBarButtonItem alloc] initWithImage:regImage style:UIBarButtonItemStylePlain target:self action:@selector(clickRegButton)];
    
    self.navigationItem.leftBarButtonItem = cancelBarButtonItem;
    self.navigationItem.rightBarButtonItem = regBarButtonItem;
    
    //mainScrollView
    _mainScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:_mainScrollView];
    
    UIView* bgView = [[UIView alloc] initWithFrame:_mainScrollView.bounds];
    [_mainScrollView addSubview:bgView];
    
    //输入框背景
    UIImage* inputBgImage = [UIImage imageNamed:@"img_login_input_bg"];
    UIImageView* inputBgImageView = [[UIImageView alloc] initWithImage:inputBgImage];
    [bgView addSubview:inputBgImageView];
    
    [inputBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@(15));
        make.right.mas_equalTo(@(-15));
        make.top.mas_equalTo(@(50));
        make.size.mas_equalTo(CGSizeMake(inputBgImage.size.width, inputBgImage.size.height));
    }];
    
    //登录按钮
    UIImage* loginBtnImage = [UIImage imageNamed:@"img_long_btn_bg"];
    UIButton* loginButton = [[UIButton alloc] init];
    [loginButton setBackgroundImage:loginBtnImage forState:UIControlStateNormal];
    [loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [bgView addSubview:loginButton];
    
    [loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@(margin_left_right_space));
        make.right.mas_equalTo(@(-margin_left_right_space));
        make.top.equalTo(inputBgImageView.mas_bottom).with.offset(34);
        make.size.mas_equalTo(CGSizeMake(loginBtnImage.size.width, loginBtnImage.size.height));
    }];
    
    //忘记密码
    UIImage* forgetImageBtn = [UIImage imageNamed:@"img_forget_pwd_btn"];
    UIButton* forgetButton = [[UIButton alloc] init];
    [forgetButton setImage:forgetImageBtn forState:UIControlStateNormal];
    [bgView addSubview:forgetButton];
    
    [forgetButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(@(-margin_left_right_space));
        make.top.equalTo(loginButton.mas_bottom).with.offset(20);
        make.size.mas_equalTo(CGSizeMake(forgetImageBtn.size.width, forgetImageBtn.size.height));
    }];
    
    //分割线
    UIImage* lineImage = [UIImage imageNamed:@"img_line"];
    UIImageView* lineImageView = [[UIImageView alloc] initWithImage:lineImage];
    [lineImageView setContentMode:UIViewContentModeScaleAspectFit];
    [bgView addSubview:lineImageView];
    
    [lineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(@(-370/2));
        make.left.mas_equalTo(@(margin_left_right_space));
        make.right.mas_equalTo(@(-margin_left_right_space));
        make.height.mas_equalTo(lineImage.size.height);
    }];
    
    //提示
    UIImage* tishiStrImage = [UIImage imageNamed:@"img_tishi_str"];
    UIImageView* tishiStrImageView = [[UIImageView alloc] initWithImage:tishiStrImage];
    [lineImageView addSubview:tishiStrImageView];
    
    [tishiStrImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(lineImageView);
        make.size.mas_equalTo(CGSizeMake(tishiStrImage.size.width, tishiStrImage.size.height));
    }];
    
    //第三方登录 QQ 微信  微博
    UIImage* qqbtnImage = [UIImage imageNamed:@"img_qq_btn"];
    UIImage* wechatBtnImage = [UIImage imageNamed:@"img_wechat_btn"];
    UIImage* weiboBtnImage = [UIImage imageNamed:@"img_weibo_btn"];
    
    
    UIButton* qqButton = [[UIButton alloc] init];
    [qqButton setImage:qqbtnImage forState:UIControlStateNormal];
    UIButton* wechatButton = [[UIButton alloc] init];
    [wechatButton setImage:wechatBtnImage forState:UIControlStateNormal];
    UIButton* weiboButton = [[UIButton alloc] init];
    [weiboButton setImage:weiboBtnImage forState:UIControlStateNormal];
    
    [bgView addSubview:qqButton];
    [bgView addSubview:wechatButton];
    [bgView addSubview:weiboButton];
    
    [qqButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineImageView.mas_bottom).with.offset(30);
        make.left.mas_equalTo(@(40));
        make.size.mas_equalTo(CGSizeMake(qqbtnImage.size.width, qqbtnImage.size.height));
    }];
    
    [wechatButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(qqButton);
        make.centerX.equalTo(bgView);
        make.size.mas_equalTo(CGSizeMake(wechatBtnImage.size.width, wechatBtnImage.size.height));
    }];
    
    [weiboButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(qqButton);
        make.right.mas_equalTo(@(-40));
        make.size.mas_equalTo(CGSizeMake(weiboBtnImage.size.width, weiboBtnImage.size.height));
    }];
}
#pragma mark- Click Event
- (void)clickCancelButton{
    [[UINavigationBar appearance] setBarTintColor:MAINGREENCOLOR];
    
    [self dismissViewControllerAnimated:YES completion:^{
       
    }];
}
- (void)clickRegButton{
    RegisterViewController* registerVC = [[RegisterViewController alloc] init];
    [self.navigationController pushViewController:registerVC animated:YES];
}
#pragma mark-
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
